package com.universal.frame.pulltorefresh;

import android.content.Context;
import android.support.v4.widget.SwipeRefreshLayout;
import android.util.Log;

import com.universal.frame.R;

public class PullToRefreshUtil {

    static final String LOG_TAG = "PullToRefresh";

    public static void warnDeprecation(String depreacted, String replacement) {
        Log.w(LOG_TAG, "You're using the deprecated " + depreacted + " attr, please switch over to " + replacement);
    }


    public static void initSwipeRefreshLayoutColor(Context context,
                                                   SwipeRefreshLayout refreshLayout) {

        refreshLayout.setColorSchemeResources(R.color.colorWarn,
                R.color.colorTextAssist, R.color.colorWarmWarn);
    }

    public static void setPullToRefreshListViewMode(Context context,
                                                    PullToRefreshListView pullRefreshListView, int listSize) {

        // 刷新完成
        pullRefreshListView.onRefreshComplete();
        // ListView listView = pullRefreshListView.getRefreshableView();
        if (listSize == 0) {
            pullRefreshListView.setMode(PullToRefreshBase.Mode.DISABLED);
        } else {
            if (listSize < 10) {
                pullRefreshListView.setMode(PullToRefreshBase.Mode.DISABLED);
            } else {
                pullRefreshListView.setMode(PullToRefreshBase.Mode.PULL_FROM_END);
            }
        }
    }

    public static void setPullToRefreshScrollViewMode(Context context,
                                                      PullToRefreshScrollView pullToRefreshScrollView, int listSize) {

        // 刷新完成
        pullToRefreshScrollView.onRefreshComplete();
        // ListView listView = pullRefreshListView.getRefreshableView();
        if (listSize == 0) {
            pullToRefreshScrollView.setMode(PullToRefreshBase.Mode.DISABLED);
        } else {
            if (listSize < 10) {
                pullToRefreshScrollView.setMode(PullToRefreshBase.Mode.DISABLED);
            } else {
                pullToRefreshScrollView.setMode(PullToRefreshBase.Mode.PULL_FROM_END);
            }
        }
    }

    /**
     * 是否关闭刷新动画
     */
    public static void isEnabled(SwipeRefreshLayout mSwipeRefreshLayout) {
        mSwipeRefreshLayout.setEnabled(true);
        if (mSwipeRefreshLayout.isRefreshing()) {
            mSwipeRefreshLayout.setRefreshing(false);
        }
    }
}
